﻿@model DHQGHN.PM0.Models.Admin.ApplicationModel
@Html.ValidationSummary(false)
@using (
                Html.BeginForm(
                    actionName: "actionCreateOrUpdateApp", controllerName: "Application", routeValues: new { }, method: FormMethod.Post, htmlAttributes: new { @id = "app-form", @class = "form-inline", @role = "form", @style = "width: 100%;" }
                    )
                )
{
    <div class="modal-body min-width">
        <div class="form-group">
            @Html.AntiForgeryToken()
            @Html.HiddenFor(m => m.AppId)
            @Html.ValidationMessageFor(m=>m.AppId,null, new { @class = "Validation_Error" })
            <div>
                @Html.LabelFor(m => m.AppName, new { @class = "labels", style = "width:100px;" })<span class="field-validation-error"> * </span>
                @Html.TextBoxFor(m => m.AppName, new { @class = "TextBoxContent", style = "width:260px", @placeholder = "" })
                @Html.ValidationMessageFor(m => m.AppName, null, new { @class = "Validation_Error" })
            </div>
            <div style="margin-top:4px;">
                @Html.LabelFor(m => m.AppCode, new { @class = "labels", style = "width:100px;" })<span class="field-validation-error"> * </span>
                @Html.TextBoxFor(m => m.AppCode, new { @class = "TextBoxContent", style = "width:260px", @placeholder = "", @id = "AppCode" })
                @Html.ValidationMessageFor(m => m.AppCode, null, new { @class = "Validation_Error" })
            </div>
            <div style="margin-top:4px;">
                @Html.LabelFor(m => m.AppDescription, new { @class = "labels", style = "width:100px;" })<span class="field-validation-error"> &nbsp; </span>
                @Html.TextAreaFor(m => m.AppDescription, new { @style = "vertical-align:top; width:260px", @class = "TextAreaContent", @placeholder = "", @cols = 80, @rows = 10 })
                @Html.ValidationMessageFor(m => m.AppDescription, null, new { @class = "Validation_Error" })
            </div>

        </div>
        @*<div class="modal-footer">
            <button type="submit" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-floppy-disk"></span>Lưu</button>
            <button type="button" class="btn btn-primary btn-sm btn-close" data-dismiss="modal"><span class="glyphicon glyphicon-off"></span>Đóng</button>
        </div>*@
    </div>
}
<div id="overlay" class="web_dialog_overlay"></div>
@Scripts.Render("~/bundles/jqueryval")
<script>
        @functions{
            public string GetAntiForgeryToken()
            {
                string cookieToken, formToken;
                AntiForgery.GetTokens(null, out cookieToken, out formToken);                                
                return cookieToken + "," + formToken;
            }
        }
</script>
<script>
    $(document).ready(function () {
        $("#AppCode").keyup(function () {
            $(this).val($(this).val().toUpperCase());
        });
    });

    var $appForm = $("#app-form");

    function save() {
        var appname = $('#AppName');
        var appcode = $('#AppCode');
        var appid = $('#AppId').val();
        appname = appname != null ? appname.val().trim() : "";
        appcode = appcode != null ? appcode.val().trim() : "";
        var result = false;
        if ($appForm.valid()) {
            //Neu chua ton tai Ung dung thi goi action them moi/cap nhat
            $.ajax({
                type: "POST",
                url: $appForm.attr('action'),
                data: $appForm.serialize(),
                dataType: '',//chú ý là form đặc biệt thì phải điền trường này
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                async: false,
                success: function (response) {
                    if (response != null && response.status == 200) {
                        window.notice(response.result, window.notice_success);
                        OnCriteria(crrPageIndex);
                        result = true;
                    } else {
                        window.notice(response.result, window.notice_error);
                    }
                }
            });
        }
        return result;
    }
</script>